#!/bin/bash

# 下载PyCharm Linux软件
echo "download pycharm"
# 安装软件

installfile="pycharm-professional-2019.1.1.tar.gz"
if [ -f $installfile ];then
	echo "文件 $installfile 存在"
	echo "Install ..."
	sudo mkdir /opt/pycharm
	sudo tar -xzvf $installfile -C /opt/pycharm
else
	echo "文件 $installfile 不存在"
	exit 1
fi
# 在桌面建立启动方式
echo "create start link ..."
if [ -d "/home/$LOGNAME/Desktop/" ];then
	echo "文件夹 dirs 存在"
	echo "[Desktop Entry]" > ~/Desktop/PyCharm.desktop
	echo "Name=PyCharm" >> ~/Desktop/PyCharm.desktop
	echo "Comment=python edit" >> ~/Desktop/PyCharm.desktop
	echo "Exec=/usr/local/bin/charm" >> ~/Desktop/PyCharm.desktop
	echo "Icon=/opt/pycharm/pycharm-2019.1.1/bin/pycharm.png" >> ~/Desktop/PyCharm.desktop
	echo "Type=Application" >> ~/Desktop/PyCharm.desktop
	echo "Categories=Development;Education;Science;" >> ~/Desktop/PyCharm.desktop
	echo "StartupNotify=true" >> ~/Desktop/PyCharm.desktop
	echo "Keywords=Run;" >> ~/Desktop/PyCharm.desktop
else # 文件夹名为  桌面
	echo "文件夹 dirs 不存在"
	echo "[Desktop Entry]" > ~/桌面/PyCharm.desktop
	echo "Name=PyCharm" >> ~/桌面/PyCharm.desktop
	echo "Comment=python edit" >> ~/桌面/PyCharm.desktop
	echo "Exec=/usr/local/bin/charm" >> ~/桌面/PyCharm.desktop
	echo "Icon=/opt/pycharm/pycharm-2019.1.1/bin/pycharm.png" >> ~/桌面/PyCharm.desktop
	echo "Type=Application" >> ~/桌面/PyCharm.desktop
	echo "Categories=Development;Education;Science;" >> ~/桌面/PyCharm.desktop
	echo "StartupNotify=true" >> ~/桌面/PyCharm.desktop
	echo "Keywords=Run;" >> ~/桌面/PyCharm.desktop
fi


# 删除文件
if [ -f $installfile ];then
	echo "删除 $installfile 文件..."
	rm pycharm-professional-2019.1.1.tar.gz
fi
